package com.leo.springbootmultithreadbasic.synchronizedkey.synchronizedcodeblock.synchronizedclass;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Leo
 * @version V1.0
 */
public class MyService {

    private static final Logger logger = LoggerFactory.getLogger(MyService.class);

    public void test1() {
        synchronized (MyService.class) {
            logger.info("test1 begin time: {}", System.currentTimeMillis());
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            logger.info("test1 end time: {}", System.currentTimeMillis());
        }
    }

    public void test2() {
        synchronized (MyService.class) {
            logger.info("test2 begin time: {}", System.currentTimeMillis());
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            logger.info("test2 end time: {}", System.currentTimeMillis());
        }
    }
}
